#ifndef FRMSERIALPORT_H
#define FRMSERIALPORT_H

#include <QWidget>
#include <QSerialPort>
#include <QTimer>
#include "frmmain.h"

namespace Ui {
class frmserialport;
}

class frmserialport : public QWidget
{
    Q_OBJECT

public:
    explicit frmserialport(QWidget *parent = nullptr);
    ~frmserialport();

private slots:
    void on_connectButton_clicked();
    void on_enterCommandModeButton_clicked();
    void on_exitCommandModeButton_clicked();
    void on_queryModeButton_clicked();
    void on_setModeButton_clicked();
    void on_querySelfCheckButton_clicked();
    void on_queryAccelButton_clicked();
    void on_setAccelButton_clicked();
    void on_queryTiltButton_clicked();
    void on_setTiltButton_clicked();
    void on_queryNtripButton_clicked();
    void on_setNtripButton_clicked();
    void on_serialDataReceived(const QString &data);
    void on_commandModeTimeout();
    void on_statusTimeout();

private:
    Ui::frmserialport *ui;
    frmmain *mainWindow;
    bool isCommandMode;
    bool waitingForCommandModeResponse;
    bool waitingForStatusResponse;
    QTimer *commandModeTimer;
    QTimer *statusTimer;

    void updatePorts();
    void sendCommandModeCommand(bool enter);
    void enableConfigControls(bool enable);
    void updateMainResponse(const QString &msg);
};

#endif // FRMSERIALPORT_H